package com.monlyu.vo;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

import com.monlyu.annotation.Comment;
import com.monlyu.util.HashUtil;

/**
 * 用户对于的角色
 * 
 * @since 2010-1-7
 */
@Entity
@Table(name = "t_u2r")
@IdClass(value = User2Role.class)
@Comment(common = "用户角色对应表")
public class User2Role extends BaseVo implements Serializable {

	private static final long serialVersionUID = 5008202718941597070L;

	@Id
	@Column(name = "u2r_userId", nullable = false)
	@Comment(common = "用户编号")
	private Long userId;

	@Id
	@Column(name = "u2r_roleId", nullable = false)
	@Comment(common = "角色编号")
	private Long roleId;

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Long getUserId() {
		return userId;
	}

	public void setRoleId(Long roleId) {
		this.roleId = roleId;
	}

	public Long getRoleId() {
		return roleId;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof User2Role) {
			return HashUtil.equals(roleId, ((User2Role) obj).roleId)
					&& HashUtil.equals(userId, ((User2Role) obj).userId);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return HashUtil.hash(userId, roleId);
	}

}
